<template>
	<view class="">
		<uni-nav-bar left-icon="back" right-text="筛选" title="成绩" @clickLeft="backpage()" @clickRight="changelist()">
		</uni-nav-bar>
		<view class="warp">
			<view class="box">
				<t-table @change="change">
					<t-tr>
						<t-th v-for="(item,index) in headList" :key="index">{{item}}</t-th>
						<!-- 	<t-th>总分</t-th>
						<t-th>数学</t-th> -->
					</t-tr>
					<t-tr v-for="item in tableList" :key="item.id">
						<t-td v-for="(items,index) in headList" :key="index">{{ item[items] }}</t-td>
					</t-tr>
				</t-table>
			</view>
		</view>
	</view>
</template>

<script>
	import tTable from '@/components/t-table/t-table.vue';
	import tTh from '@/components/t-table/t-th.vue';
	import tTr from '@/components/t-table/t-tr.vue';
	import tTd from '@/components/t-table/t-td.vue';
	export default {
		components: {
			tTable,
			tTh,
			tTr,
			tTd
		},
		data() {
			return {
				tableList: [],
				headList: [],
				examRoom: [],
				roomList: [],
				examId: 0
			};
		},
		onLoad(options) {
			this.getRoom();
		},
		methods: {
			backpage(){
				uni.navigateBack({
					delta:1
				})
			},
			changelist() {
				let this_ = this;
				uni.showActionSheet({
					itemList: this_.roomList,
					success: function(res) {
						this_.examId = this_.examRoom[res.tapIndex].id;
						this_.getData();
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			getRoom() {
				let this_ = this;
				let opts = {
					url: 'Ls/SearchKssjd.shtml'
				};
				let param = {
					token: uni.getStorageSync('userInfo').token,
					class_code: uni.getStorageSync('classcode')
				};
				this_.$http.httpRequest(opts, param).then(
					res => {
						if (res.data.code == '200') {
							this_.examRoom = res.data.data;

							this_.examRoom.forEach((item, index) => {
								if (index == 0) {
									this_.examId = this_.examRoom[index].id
									this.getData();
								}
								this_.roomList.push(this_.examRoom[index].name);
							})
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					},
					error => {
						console.log(error);
					}
				);

			},
			getData() {
				let this_ = this;
				let opts = {
					url: 'Ls/SearchLsCj.shtml'
				};

				let param = {
					token: uni.getStorageSync('userInfo').token,
					kssjd_code: this_.examId,
					class_code: uni.getStorageSync('classcode')
				};
				this_.$http.httpRequest(opts, param).then(
					res => {
						if (res.data.code == '200') {
							let head = [];
							if (res.data.data != "") {
								let obj = res.data.data[0];
								for (let item in obj) {
									head.push(item)
								}
								this_.tableList = res.data.data
								this_.headList = head
							}
						} else {
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							});
						}
					},
					error => {
						console.log(error);
					}
				);
			}
		}
	};
</script>

<style>
	.t-td[data-v-c8197784] {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		width: 100%;
		padding: 6px;
		border-top: 1px #d0dee5 solid;
		border-left: 1px #d0dee5 solid;
		text-align: center;
		color: #555c60;
		font-size: 11px;
	}
</style>
